//
//  GiftOrderDetailViewController.swift
//  ShopIOS
//
//  Created by Apple on 2019/8/12.
//  Copyright © 2019 Apple. All rights reserved.
//

import UIKit

class GiftOrderDetailViewController: UIViewController {
    @IBOutlet weak var uv_back: UIView!
    @IBOutlet weak var lb_shipto: UILabel!
    @IBOutlet weak var lb_phone: UILabel!
    @IBOutlet weak var lb_address: UILabel!
    @IBOutlet weak var lb_ordernum: UILabel!
    @IBOutlet weak var lb_status: UILabel!
    @IBOutlet weak var iv_img: UIImageView!
    @IBOutlet weak var lb_giftname: UILabel!
    @IBOutlet weak var lb_giftvalue: UILabel!
    @IBOutlet weak var lb_count: UILabel!
    @IBOutlet weak var lb_total: UILabelPadding!
    @IBOutlet weak var lb_time: UILabelPadding!
    @IBOutlet weak var uv_address: UIView!
    @IBOutlet weak var uv_head: UIView!
    @IBOutlet weak var uv_foot: UIView!
    @IBOutlet weak var uv_time: UIView!
    var orderId:String!
    
    init(orderId:String!){
        super.init(nibName: nil, bundle: nil)
        self.orderId=orderId!
        print(orderId!)
        loaddata()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    @objc func back(){
        self.navigationController?.popViewController(animated: true)
    }
    func loaddata(){
        var d = ["app_key":app_key,
                 "id":orderId!,
                 "userkey":userkey!,
            "timestamp":getTimestamp()
            ] as [String : String]
        let sign=SignTopRequest(params: d)
        d["sign"]=sign
        AlamofireHelper.get(url: GetOrder, parameters: d, successHandler: {[weak self](res)in
            HUD.dismiss()
            guard let ss = self else {return}
            let detail=mGiftOrderDetailResult.init(json: res)
            ss.lb_shipto.text=detail.ShipTo
            ss.lb_phone.text=detail.CellPhone
            ss.lb_address.text="\(detail.RegionFullName!)\(detail.Address!)"
            ss.lb_ordernum.text="\(detail.Id)"
            ss.lb_status.text=detail.ShowOrderStatus
            if (detail.Items[0].DefaultImage != nil){
                ss.iv_img.setImage(path: URL.init(string: detail.Items[0].DefaultImage!)!)
            }
            ss.lb_giftname.text=detail.Items[0].GiftName
            ss.lb_giftvalue.text="\(detail.Items[0].SaleIntegral)西瓜币"
            ss.lb_count.text="x\(detail.Items[0].Quantity)"
            ss.lb_total.text="共1件礼品 合计：\(detail.TotalIntegral)西瓜币"
            ss.lb_time.text="兑换时间：\(detail.OrderDate?.replacingOccurrences(of: "T", with: " ") ?? "")"
            ss.lb_time.paddingLeft=10
        }){[weak self] (error) in
            HUD.dismiss()
            guard let ss = self else {return}
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        uv_address.layer.cornerRadius=5
        uv_head.layer.cornerRadius=5
        uv_head.layer.maskedCorners=CACornerMask(rawValue: CACornerMask.layerMinXMinYCorner.rawValue|CACornerMask.layerMaxXMinYCorner.rawValue)
        uv_foot.layer.cornerRadius=5
        uv_foot.layer.maskedCorners=CACornerMask(rawValue: CACornerMask.layerMinXMaxYCorner.rawValue|CACornerMask.layerMaxXMaxYCorner.rawValue)
        uv_time.layer.cornerRadius=5
        uv_back.addOnClickListener(target: self, action: #selector(back))
        
        // Do any additional setup after loading the view.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
